package com.koron.operation.classes.form.service.impl;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.koron.operation.classes.form.bean.po.ClassesFormTakeover;
import com.koron.operation.classes.form.mapper.ClassesFormTakeoverMapper;
import com.koron.operation.classes.form.service.ClassesFormTakeoverService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 班别调整-接班人信息表(ClassesFormTakeover)表服务实现类
 *
 * @author jzp
 * @since 2023-05-22 09:48:17
 */
@Service
public class ClassesFormTakeoverServiceImpl implements ClassesFormTakeoverService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public ClassesFormTakeover getById(SessionFactory factory, String id) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<ClassesFormTakeover> list(SessionFactory factory, ClassesFormTakeover classesFormTakeover) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.selectList(classesFormTakeover);
    }

    @Override
    @TaskAnnotation("listByFormId")
    public List<ClassesFormTakeover> listByFormId(SessionFactory factory, String formId) {
        ClassesFormTakeover query = new ClassesFormTakeover();
        query.setFormId(formId);
        return list(factory, query);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, ClassesFormTakeover classesFormTakeover) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.insertOrUpdate(classesFormTakeover) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<ClassesFormTakeover> takeoverList) {
        if (CollUtil.isEmpty(takeoverList)) {
            return false;
        }
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.insertOrUpdateBatch(takeoverList) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, ClassesFormTakeover classesFormTakeover) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.update(classesFormTakeover) > 0;
    }

    @Override
    @TaskAnnotation("updateChangeStatusByChangeId")
    public boolean updateChangeStatusByChangeId(SessionFactory factory, String changeId, String changeStatus) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.updateChangeStatusByChangeId(changeId, changeStatus) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByChangeId")
    public boolean removeByChangeId(SessionFactory factory, String changeId) {
        if (StrUtil.isEmpty(changeId)) {
            return false;
        }
        ClassesFormTakeoverMapper mapper = factory.getMapper(ClassesFormTakeoverMapper.class);
        return mapper.removeByChangeId(changeId) > 0;
    }

}
